from .base import Base
from sqlalchemy.types import Integer
from sqlalchemy.schema import Column, UniqueConstraint
from sqlalchemy.databases import mysql

__all__ = ["Station"]

class Station(Base):

    __tablename__ = "stations"

    id = Column(Integer, primary_key=True)
    name = Column(mysql.MSString(256), nullable=False)
    countryCode = Column(mysql.MSString(3))
    lat = Column(mysql.DECIMAL(precision=14, scale=8))
    lng = Column(mysql.DECIMAL(precision=14, scale=8))

    __table_args__ = (UniqueConstraint("name", "countryCode"), {})

    def __init__(self, name, countryCode=None):
        self.name = name
        self.countryCode = countryCode

    def __eq__(self, other):
        return (self.name == other.name) and (self.countryCode == other.countryCode)

    def __repr__(self):
        return u"<Station('%s', '%s')>" % (self.name, self.countryCode)
